import { Component, Input, OnInit, ViewChild } from '@angular/core';
import { ColumnType, SPage, TablePageComponent } from '@shared/components/table-page/table-page.component';
import { NzMessageService, NzModalService } from 'ng-zorro-antd';
import { ApiService } from '@core/services/api';
import {HttpClient} from "@angular/common/http";
import { PermissionService } from '@core/services/permission.service';
import { ACLService } from '@delon/acl';
import { STData } from '@delon/abc';
import { CostEditComponent } from '../cost-edit/cost-edit.component';
@Component({
  selector: 'app-cost-add',
  templateUrl: './cost-add.component.html',
  styles: []
})
export class CostAddComponent implements OnInit {
  @ViewChild('st', {static: false})st: TablePageComponent;
  @Input()
  set _param(value){
      console.log(value)
      if(!value) return
      this.param = value
      this.config.defaultParam = {
        areaId:[value.id],
        itemType:3
      }
  }
  param:any
  key:string="";
  ip:string="";
  config: SPage = {
    columns: [
      {
        index: 'itemName',
        title: '名称',
        filter: {
          type: 'string'
        }
      },
      {
        index: 'openType',
        title: '类型',
        type: ColumnType.tag,
        tag:{
           1:{text:'小区开通'},
           2:{text:'个人开通'}
        }
      },
      {
        index: 'monthlyRent',
        title: '费用元（1年）',
        fFn(item){
          return item.monthlyRent / 100 + ''
        }
      },
      {
        index: 'createTime',
        title: '创建时间',
      },
      // {
      //   index: '',
      //   title: '操作',
      //   buttons:[
      //     {
      //       text:'编辑',
      //       click:(_record)=>{
      //         this.editDic(_record)
      //       }
      //     }
      //   ]
      // },
    ],
    reqUrl: "/core/qr/pay/paymentPageByAreaId",
  };
  selectedData: object[];
  //数据预处理
  dataProcess(data: STData[]){
    return data;
  }
  //新增费用项
  addCost():void{
    const type = 0
    const id = this.param.id
    this.modal.create({
      nzTitle: "新增费用项",
      nzContent: CostEditComponent,
      nzWidth: 800,
      nzComponentParams: {
        type,
        id
      },
      nzOnOk: () => {
        this.st.reload();
      },
      nzFooter: null
    })
  }

  editDic(_param?: object): void {
    const type=1
    this.modal.create({
      nzTitle: "编辑",
      nzContent: CostEditComponent,
      nzWidth: 800,
      nzComponentParams: {
        type,
        _param
      },
      nzOnOk: () => {
        this.st.reload();
      },
      nzFooter: null
    })
  }
  _selectChange(e): void {
    this.selectedData = e;
  }

  selectChange(event): void {
    this.st.searchData({areaParentId: event.keys[0]});
  }

 
  constructor(
    private modal: NzModalService,
    private msg: NzMessageService,
    private api: ApiService,
    private http: HttpClient,
    private permission: PermissionService,
    private aclService: ACLService
  ) { }


  ngOnInit() {
  
  }
}
